package com.yonglian.management.service.impl;

import com.yonglian.management.domain.ActivityProperty;
import com.yonglian.management.repository.ActivityPropertyRepository;
import com.yonglian.management.service.ActivityPropertyService;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link com.yonglian.management.domain.ActivityProperty}.
 */
@Service
@Transactional
public class ActivityPropertyServiceImpl implements ActivityPropertyService {

    private final Logger log = LoggerFactory.getLogger(ActivityPropertyServiceImpl.class);

    private final ActivityPropertyRepository activityPropertyRepository;

    public ActivityPropertyServiceImpl(ActivityPropertyRepository activityPropertyRepository) {
        this.activityPropertyRepository = activityPropertyRepository;
    }

    @Override
    public ActivityProperty save(ActivityProperty activityProperty) {
        log.debug("Request to save ActivityProperty : {}", activityProperty);
        return activityPropertyRepository.save(activityProperty);
    }

    @Override
    public ActivityProperty update(ActivityProperty activityProperty) {
        log.debug("Request to update ActivityProperty : {}", activityProperty);
        return activityPropertyRepository.save(activityProperty);
    }

    @Override
    public Optional<ActivityProperty> partialUpdate(ActivityProperty activityProperty) {
        log.debug("Request to partially update ActivityProperty : {}", activityProperty);

        return activityPropertyRepository
            .findById(activityProperty.getId())
            .map(existingActivityProperty -> {
                if (activityProperty.getPropertyName() != null) {
                    existingActivityProperty.setPropertyName(activityProperty.getPropertyName());
                }
                if (activityProperty.getPropertyValue() != null) {
                    existingActivityProperty.setPropertyValue(activityProperty.getPropertyValue());
                }
                if (activityProperty.getPropertyRemark() != null) {
                    existingActivityProperty.setPropertyRemark(activityProperty.getPropertyRemark());
                }
                if (activityProperty.getPropertyType() != null) {
                    existingActivityProperty.setPropertyType(activityProperty.getPropertyType());
                }
                if (activityProperty.getOrderNo() != null) {
                    existingActivityProperty.setOrderNo(activityProperty.getOrderNo());
                }

                return existingActivityProperty;
            })
            .map(activityPropertyRepository::save);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<ActivityProperty> findAll(Pageable pageable) {
        log.debug("Request to get all ActivityProperties");
        return activityPropertyRepository.findAll(pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Optional<ActivityProperty> findOne(Long id) {
        log.debug("Request to get ActivityProperty : {}", id);
        return activityPropertyRepository.findById(id);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete ActivityProperty : {}", id);
        activityPropertyRepository.deleteById(id);
    }
}
